﻿using System;
using System.IO;

namespace FMStudio.Documents.Test
{
    public class MockDocumentType : DocumentType<MockDocument>
    {
        public MockDocumentType(string description, string fileExtension)
            : base(description, fileExtension)
        {
            this.CanSaveResult = true;
        }


        #region Properties
        public bool CanSaveResult { get; set; }

        public DocumentOperation DocumentOperation { get; private set; }

        public string FilePath { get; private set; }

        public bool ThrowException { get; set; }
        #endregion

        #region Methods
        #region Public Methods
        public void Clear()
        {
            this.DocumentOperation = DocumentOperation.None;
            this.FilePath = null;
        }


        public override bool CanNew() { return true; }

        public override bool CanOpen() { return true; }
        #endregion

        #region Protected Methods
        protected override MockDocument NewCore(string fullFilePath)
        {
            CheckThrowException();
            this.DocumentOperation = DocumentOperation.New;
            this.FilePath = fullFilePath;
            return new MockDocument();
        }

        protected override MockDocument OpenCore(string fullFilePath)
        {
            CheckThrowException();
            this.DocumentOperation = DocumentOperation.Open;
            this.FilePath = Path.GetFullPath(fullFilePath);
            return new MockDocument();
        }

        protected override bool CanSaveCore() { return CanSaveResult; }

        protected override void SaveCore(MockDocument document, string fullFilePath)
        {
            CheckThrowException();
            this.DocumentOperation = DocumentOperation.Save;
            this.FilePath = Path.GetFullPath(fullFilePath);
        }
        #endregion

        #region Private Methods
        private void CheckThrowException()
        {
            if (ThrowException) { throw new InvalidOperationException("ThrowException has been activated on the MockDocumentType."); }
        }
        #endregion
        #endregion



    }

    public enum DocumentOperation
    {
        None,
        New,
        Open,
        Save
    }

    public class MockDocument : Document
    {
        public MockDocument()
        {
        }
    }
}
